<!--
 * @Author: 何 海深 813936564@qq.com
 * @Date: 2023-03-01 14:09:51
 * @LastEditors: 何 海深 813936564@qq.com
 * @LastEditTime: 2023-12-01 21:41:06
 * @FilePath: \datashowapicture\src\components\self-message\SelfMessage.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <transition name="fade">
    <div v-if="isShow" class="s-message" :style="MESSAGE_STYLE[props.type]">
      <!-- <s-icon :icon="MESSAGE_STYLE[props.type].icon" /> -->
      <span class="text">{{ props.text }}</span>
    </div>
  </transition>
</template>

<script lang="ts" setup>
import { ref, onMounted } from 'vue'
import { MESSAGE_TIMEOUT, MESSAGE_STYLE } from './configData' // 参见上面的常量
const props = defineProps({
  // 消息文本
  text: {
    type: String,
    default: ''
  },
  // 消息类型： "info" | "success" | "warn" | "error"
  type: {
    type: String,
    default: 'warn'
  },
  // 消息停留时间
  timeout: {
    type: Number,
    default: MESSAGE_TIMEOUT
  }
})

// 组件状态
const isShow = ref<boolean>(false)

// 注册定时器控制组件的消失
onMounted(() => {
  isShow.value = true
  setTimeout(() => {
    isShow.value = false
  }, props.timeout)
})
</script>

<style scoped lang="scss">
.fade-enter-active {
  animation: fade 0.5s;
}
.fade-leave-active {
  animation: fade 0.5s reverse;
}

/* 定义帧动画 */
@keyframes fade {
  0% {
    opacity: 0;
    transform: translateY(-50vw * $Bw);
  }

  100% {
    opacity: 1;
  }
}

.s-message {
  min-width: 300vw * $Bw;
  max-width: 350vw * $Bw;
  padding: 8vh * $Bh 10vw * $Bw;
  position: fixed;
  z-index: 9999;
  left: 50%;
  margin-left: -150vw * $Bw;
  top: 25vw * $Bw;
  border-radius: 4vw * $Bw;
  display: flex;
  justify-content: center;
  .text {
    vertical-align: middle;
    text-align: center;
  }
}
</style>
